/*

This file is part of roomyak.

Copyright (C) 2008 Pixecur Technologies Incorporated (Esotera).
Visit Esotera at http://www.esoteras3.com
 
roomyak is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
 
roomyak is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with roomyak; see the file COPYING.  If not, write to 
Pixecur Technologies, 213-31 Peet Street, St. John's, NL, A1B 3W8. 
 
Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
 
*/

package com.datasentinel.util.concurrent;

import java.util.Date;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.logging.Logger;

class NamedCondition implements Condition
{
	private NamedReentrantLock ownerLock;
	private Condition condition;
	private Logger logger;
	
	public NamedCondition(NamedReentrantLock ownerLock, Condition condition, Logger logger)
	{
		this.ownerLock = ownerLock;
		this.condition = condition;
		this.logger = logger;
	}
	
	@Override
	public void await() throws InterruptedException
	{
		logger.log(NamedReentrantLock.LOGGER_LEVEL, ownerLock.getName() + ": condition.AWAIT(...)");
		condition.await();
	}

	@Override
	public boolean await(long time, TimeUnit unit) throws InterruptedException
	{
		logger.log(NamedReentrantLock.LOGGER_LEVEL, ownerLock.getName() + ": condition.AWAIT(.." + time + " " + unit.toString() + "..)");
		return condition.await(time, unit);
	}

	@Override
	public long awaitNanos(long nanosTimeout) throws InterruptedException
	{
		return condition.awaitNanos(nanosTimeout);
	}

	@Override
	public void awaitUninterruptibly()
	{
		condition.awaitUninterruptibly();
	}

	@Override
	public boolean awaitUntil(Date deadline) throws InterruptedException
	{
		return condition.awaitUntil(deadline);
	}

	@Override
	public void signal()
	{
		logger.log(NamedReentrantLock.LOGGER_LEVEL, ownerLock.getName() + ": condition.SIGNAL( Oo.oO )");
		condition.signal();
	}

	@Override
	public void signalAll()
	{
		logger.log(NamedReentrantLock.LOGGER_LEVEL, ownerLock.getName() + ": condition.SIGNAL_ALL( **Oo.oO** )");
		condition.signalAll();
	}

}
